<template>
  <div class="container">
    <!-- 数据大屏展示内容的区域 -->
    <div ref="screenRef" class="screen">
      <!-- 数据大屏顶部 -->
      <div class="top">
        <Top></Top>
      </div>
      <!-- 数据大屏底部 -->
      <div class="bottom">
        <!-- 左边图表 -->
        <div class="left">
          <Tourist></Tourist>
          <Gender></Gender>
          <Age></Age>
        </div>
        <!-- 中间图表 -->
        <div class="center">
          <Map></Map>
          <Line></Line>
        </div>
        <!-- 右侧图表 -->
        <div class="right">
          <Rank></Rank>
          <YearTour></YearTour>
          <Counter></Counter>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
// 顶部组件
import Top from "./components/top/index.vue";
// 底部左侧组件-游客比例
import Tourist from "./components/tourist/index.vue";
// 底部左侧组件-性别比例
import Gender from "./components/gender/index.vue";
// 底部左侧组件-年龄比例
import Age from "./components/age/index.vue";
// 底部中间组件-地图
import Map from "./components/map/index.vue";
// 底部中间组件-折线图
import Line from "./components/line/index.vue";
// 底部右侧组件-景区排行
import Rank from "./components/rank/index.vue";
// 底部右侧组件-年度游客量对比
import YearTour from "./components/year/index.vue";
// 底部右侧组件-渠道统计
import Counter from "./components/counter/index.vue";
// 获取数据大屏展示内容盒子的DOM元素
const screenRef = ref();

onMounted(() => {
  // 页面渲染完成时，改变一次screen盒子的位置
  screenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
});
// 获取数据大屏缩放的比例
const getScale = (w = 1920, h = 1080) => {
  // 视口缩放了多少，大屏展示内容的盒子就缩放多少
  // window.innerWidth / innerHeight 指的是当前视口的宽度和高度
  let ww = window.innerWidth / w;
  let wh = window.innerHeight / h;
  return ww < wh ? ww : wh;
};
window.onresize = () => {
  screenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
};
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 100vh;
  background: url(./images/bg.png);
  background-size: cover;
  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    left: 50%;
    top: 50%;
    transform-origin: left top;
    .top {
      width: 100%;
      height: 40px;
    }
    .bottom {
      display: flex;
      width: 100%;
      height: 1040px;
      padding-bottom: 20px;
      .left {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-left: 20px;
      }
      .right {
        flex: 1;
        display: flex;
        flex-direction: column;
        margin-right: 20px;
      }
      .center {
        flex: 2;
        display: flex;
        flex-direction: column;
      }
    }
  }
}
</style>
